package it.mp.acquaalta.utility;

import it.mp.acquaalta.widget.R;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DatiAdapter extends ArrayAdapter<AcquaAltaBean.Bean> {	 
        private ArrayList<AcquaAltaBean.Bean> esercizi;
        private Context mContext;

        public DatiAdapter(Context context, int textViewResourceId, ArrayList<AcquaAltaBean.Bean> items) {
                super(context, textViewResourceId, items);
                this.esercizi = items;
                mContext=context;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                View v = convertView;
                
                if (v == null) {                	
                    LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    v = vi.inflate(R.layout.acquaalta_riga, null);
                }

                AcquaAltaBean.Bean bean = esercizi.get(position);
                if (bean != null) {
                	  ((ImageView)v.findViewById(R.id.IV_quad)).setImageResource(bean.getQuadratino());
                	  
                	  ((TextView)v.findViewById(R.id.TV_giorno)).setText(bean.getDataWidget());                	  
                	  ((TextView)v.findViewById(R.id.TV_ora)).setText(bean.getOrario());                	  
                	  ((TextView)v.findViewById(R.id.TV_val)).setText(bean.valore);
                	  if ("minimo".equals(bean.tipo)){
                		  ((TextView)v.findViewById(R.id.TV_tipo)).setText("min");
                	  }else{
                		  ((TextView)v.findViewById(R.id.TV_tipo)).setText("max");
                	  }
                }                 
                return v;
        }

}
